import {equlAray} from '@/utils/aryutil.js'
export default{
	namespaced:true,
	state:{
		shopcartList:JSON.parse(uni.getStorageSync("cart")||'[]')
	},
	mutations:{
		addToShopcart(state,payload){
			console.log('----mutations的addToShopcart--------');
			const result=state.shopcartList.find(item=>{
				if(item.gid==payload.gid){
					if(equlAray(item.params,payload.params)){
						return true
					}
				}
			})
			if(!result){
				state.shopcartList.push(payload)
			}else{
				result.count+=payload.count
			}
			uni.setStorageSync("cart",JSON.stringify(state.shopcartList))
		}
	},
	getters:{
		getShopcartSize(state){
			return state.shopcartList?state.shopcartList.length:0
		}
	}
}